Fix PV CPUID virtualization of XSave
authorShan Haitao <haitao.shan@intel.com>
Sat, 17 Sep 2011 23:01:58 +0000 (00:01 +0100)
committerShan Haitao <haitao.shan@intel.com>
Sat, 17 Sep 2011 23:01:58 +0000 (00:01 +0100)
The patch will fix XSave CPUID virtualization for PV guests. The XSave
area size returned by CPUID leaf D is changed dynamically depending on
the XCR0. Tools/libxc only assigns a static value. The fix will adjust
xsave area size during runtime.

Note: This fix is already in HVM cpuid virtualization. And Dom0 is not
affected, either.

Signed-off-by: Shan Haitao <haitao.shan@intel.com>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/traps.c

index bce2df8d0adad1da3fb4c3d332ba9d86f2545d78..b8225e6b981e8b054583775f4f01e39920a43a45 100644 (file)
@@ -2426,7 +2426,7 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
         {
             /* reset EBX to default value first */
             *ebx = XSTATE_AREA_MIN_SIZE; 
-            for ( sub_leaf = 2; sub_leaf < 64; sub_leaf++ )
+            for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ )
             {
                 if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) )
                     continue;
index 183ce91b74f791933c00d932d19b70949a5f6795..0203613b530dcefa2d574a6a3ef45fd12d338b60 100644 (file)
@@ -770,6 +770,30 @@ static void pv_cpuid(struct cpu_user_regs *regs)
     {
         if ( !cpuid_hypervisor_leaves(a, c, &a, &b, &c, &d) )
             domain_cpuid(current->domain, a, c, &a, &b, &c, &d);
+
+        switch ( a )
+        {
+        case 0xd:
+        {
+            unsigned int sub_leaf, _eax, _ebx, _ecx, _edx;
+            /* EBX value of main leaf 0 depends on enabled xsave features */
+            if ( c == 0 && current->arch.xcr0 )
+            {
+                /* reset EBX to default value first */
+                b = XSTATE_AREA_MIN_SIZE;
+                for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ )
+                {
+                    if ( !(current->arch.xcr0 & (1ULL << sub_leaf)) )
+                        continue;
+                    domain_cpuid(current->domain, a, c, &_eax, &_ebx, &_ecx,
+                                 &_edx);
+                    if ( (_eax + _ebx) > b )
+                        b = _eax + _ebx;
+                }
+            }
+        break;
+        }
+        }
         goto out;
     }